package com.macroye.consumer.controller;

import com.alibaba.fastjson.JSONObject;
import com.macroye.consumer.service.UserService;
import com.macroye.entity.req.BrokerLoginVo;
import com.macroye.entity.req.ConsumerLoginVo;
import com.macroye.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
@Log4j2
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    HttpServletRequest request;

    /**
     * 查找消费者
     * @return
     */
    @PostMapping("/consumerLogin")
    public Result<ConsumerLoginVo> consumerLogin(@RequestBody ConsumerLoginVo consumerLoginVo){
        log.info("请求路径：【{}】，请求方式：【{}】，请求参数：【{}】",
                request.getRequestURI(),request.getMethod(), JSONObject.toJSONString(consumerLoginVo));

        Result<ConsumerLoginVo> result=userService.consumerLogin(consumerLoginVo);

        log.info("请求路径：【{}】，请求方式：【{}】，响应结果：【{}】",
                request.getRequestURI(),request.getMethod(), result);
        return result;
    }

}
